package com.baozun.houji.me.activity.account

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.baozhun.mall.common.arouter.RoutePath
import com.baozhun.mall.common.base.BaseActivity
import com.baozhun.mall.common.util.Constants
import com.baozun.houji.me.R
import com.baozun.houji.me.databinding.ActivityResetPwdBinding
import com.baozun.houji.me.viewmodel.ResetPwdViewModel
import com.jaeger.library.StatusBarUtil


/**
 * @Title：重置密码页面
 * @Description：
 * @Author：xuefeng.zhu
 * @Since：2022/12/10
 * @Version：1.0.0
 */
@Route(path = RoutePath.Me.REGISTER)
class ResetPwdActivity : BaseActivity<ResetPwdViewModel, ActivityResetPwdBinding>() {

    val email: String by lazy { intent.getStringExtra(Constants.Common.BUNDLE_NAME).toString() }
    val ticket: String by lazy { intent.getStringExtra(Constants.SPKey.TICKET).toString() }
    val code: String by lazy { intent.getStringExtra(Constants.SPKey.CODE).toString() }

    companion object {
        fun start(context: Context, email: String, code: String, ticket: String) {
            var intent = Intent(context, ResetPwdActivity::class.java)
            intent.putExtra(Constants.Common.BUNDLE_NAME, email)
            intent.putExtra(Constants.SPKey.CODE, code)
            intent.putExtra(Constants.SPKey.TICKET, ticket)
            context.startActivity(intent)
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        StatusBarUtil.setColor(this, getColor(android.R.color.transparent))
        StatusBarUtil.setTransparentForImageView(this, mDataBinding.titleBarBack)
        mViewModel.email.value = email
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when (v?.id) {
            R.id.title_bar_back -> {
                finish()
            }

            R.id.tv_submit -> {
                mViewModel.resetPwd(email, code, ticket) {
                    ARouter.getInstance().build(RoutePath.Me.LOGIN).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
                        .navigation()
                }
            }

        }
    }

}